package com.wyh.service.serviceImpl.groupOne.customer;

import cn.hutool.core.util.ObjectUtil;
import com.wyh.common.enums.ResultCodeEnum;
import com.wyh.common.exception.CustomException;
import com.wyh.domain.po.groupOne.customer.MasterDataContacts;
import com.wyh.mapper.groupOne.customer.MasterDataContactsMapper;
import com.wyh.service.groupOne.customer.MasterDataContactsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MasterDataMasterDataContactsServiceImpl implements MasterDataContactsService {

    @Autowired
    private MasterDataContactsMapper masterDataContactsMapper;


    @Override
    public List<MasterDataContacts> selectAll(Integer id) {
        if (id == null) {
            throw new CustomException(ResultCodeEnum.ORGANIZATION_FIND_ERROR);
        }
        return masterDataContactsMapper.selectAll(id);
    }

    @Override
    public int insert(MasterDataContacts masterDataContacts) {
        masterDataContactsMapper.insert(masterDataContacts);
        return 1;
    }

    @Override
    public int update(MasterDataContacts masterDataContacts) {

        masterDataContactsMapper.update(masterDataContacts);
        return 1;
    }

    @Override
    public int delete(Integer id) {
        MasterDataContacts masterDataContacts = masterDataContactsMapper.selectById(id);
        if (!ObjectUtil.isEmpty(masterDataContacts)) {

            return masterDataContactsMapper.delete(id);
        }
        throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
    }

    @Override
    public List<MasterDataContacts> selectByCustomerId(Integer id) {
        return masterDataContactsMapper.selectByCustomerId(id);
    }


}
